<template>
	<view class="add page c00">
		<view class="bgf7 p12">
			<view class="bgff px14 pb10">
				
				<view class="flex flexC  borb py12" >
					<text class="flex1">所属店铺</text>
					<text class="py3 " >{{selectShop.name}}</text>
				</view>
				
				<view class="flex flexC borb py12">
					<text class="flex1">WiFi名字</text>
					<input v-model="name" class=" aliR py3" placeholder="请输入Wifi" />

				</view>
				<view class="flex flexC  py12">
					<text class="flex1">WiFi密码</text>
					<input v-model="password" type="text" class=" aliR  py3" placeholder="请输入WiFi密码" />

				</view>


			</view>
			<view class="flex flexC flexJC py20">
				<view class="aliC py12 w-17 bg41 r40" @click="save">保存</view>
			</view>



		</view>


	</view>
</template>

<script>

	export default {
	
		data() {
			return {
				shop_id: '',
				password: '',
				name:'',
				selectShop:null,
			
			};
		},
		onLoad(option) {

			var shop = option.selectShop;
			this.selectShop = JSON.parse(shop);
		},

		onShow() {
			this.getInfo();
		},
		methods: {

			
			getInfo(){
				
				let param = {
					shop_id: this.selectShop.id,
					
				};
				let that = this;
				this.$api.getShopWifi(param).then(res => {
				
					if (res.code == 1) {
						if(res.data != null){
							that.name = res.data.wifi_name;
							that.password = res.data.wifi_password;
							
						}
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},



			save() {

				if (this.name == '') {

					uni.showToast({
						title: "请填名字",
						icon: 'none'
					})
					return;
				}


				if (this.password == '') {

					uni.showToast({
						title: "请填写密码",
						icon: 'none'
					})
					return;
				}


				let param = {
					shop_id: this.selectShop.id,
					name: this.name,
					password:this.password,
				};
				let that = this;
				this.$api.addWifi(param).then(res => {

					if (res.code == 1) {
						uni.showModal({
							title: "设置提示",
							content: "设置成功",
							showCancel: false,
							complete() {
								uni.navigateBack({
									delta: 1
								})
							}
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.add {
		.w48 {
			width: 96rpx;
			height: 96rpx;
		}

		.imgbox {
			width: 164rpx;
			height: 164rpx;
			background-color: #E8E8E8;
			position: relative;

			image {
				width: 100%;
				height: 100%;
			}

			.del {
				width: 36rpx;
				height: 36rpx;
				background: rgba(181, 180, 180, .8);
				position: absolute;
				top: -12rpx;
				right: -12rpx;
			}
		}
	}

	.popup-content2 {
		background: #FFFFFF;

		.popup-btn {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			border-bottom: 1px solid #f5f5f5;
			background: #FFFFFF;
		}

		.button {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			border-bottom: 1px solid #f5f5f5;
			background: #FFFFFF;
			font-size: 11pt;
		}

		button::after {
			border: none;
		}

		.pt20 {
			border-bottom: 20rpx solid #f5f5f5;
		}
	}
</style>
